﻿using System.Collections;

namespace Map_Creator.RedoUndo.Actions
{
    class ListReplaceAction : IAction
    {
        private IList list;
        private int index;
        private object prevItem;
        private object newItem;

        public ListReplaceAction(IList list, int index, object newItem)
        {
            this.list = list;
            this.index = index;
            this.newItem = newItem;
            prevItem = list[index];
        }

        public void Do()
        {
            list[index] = newItem;
        }

        public void Undo()
        {
            list[index] = prevItem;
        }

        public string GetDescription()
        {
            return "Replace " + prevItem + " With " + newItem + "At List";
        }

        public string GetName()
        {
            return "List Replace";
        }
    }
}
